package cn.bugstack.domain.strategy.model.entity;

import cn.bugstack.types.common.Constants;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

/**
 * 策略实体类
 */

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class StrategyEntity {

    //抽奖策略ID
    private Long strategyId;
    //策略规则 rule_weight,rule_blacklist
    private String ruleModels;
    //抽奖策略描述
    private String strategyDesc;

    //充血 获取 ruleModels 的 策略规则并进行解析
    public String[] ruleModels(){
        if(StringUtils.isBlank(ruleModels)){
            return null;
        }
        return ruleModels.split(Constants.SPLIT);
    }

    public String getRuleWeight(){
        String[] ruleModels = this.ruleModels();
        if(ruleModels == null){
            return null;
        }
        for(String ruleModel : ruleModels){
            if("rule_weight".equals(ruleModel)){
                return ruleModel;
            }
        }
        return null;
    }

}
